<template>
  <div class="m-message_detail">
    <el-form class="form" ref='form' label-width="120px">
      <el-form-item label="公告标题：">
        {{ form.title }}
      </el-form-item>
      <el-form-item label="公告内容：">
        <div v-html='form.content'></div>
      </el-form-item>
      <el-form-item label="公告时间：">
        {{ form.release_time | filterTime }}
      </el-form-item>
      <el-form-item label='发布人：'>
        {{ form.releaser_name }}
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import oObserver from '@/util/eventBus'

export default {

  name: 'm-message_detail',

  data() {
    return {
      form: {
        title: '',
        release_time: new Date(),
        releaser_name: '',
        content: ''
      }
    }
  },

  mounted() {
    const { id } = this.$route.query
    if (!id) {
      return false
    }
    this.read(id)
    this.getDetail(id)
  },

  methods: {
    async getDetail(id) {
      const { code, data } = await this.$api.linkGetNoticeInfo({ aId: id })
      if (code === 0 && data) {
        this.form = data
      }
    },

    async read(id) {
      const { code } = await this.$api.userReadMessages({
        aFirmId: this.aFirmId,
        aMessageIds: [id]
      })
      if (code === 0) oObserver.dispatch('updateFirmId')
    }
  },

  filters: {
    filterTime: (value) => {
      const d = new Date(parseInt('' + value + '000', 10))
      return window.$tools.formatDate(d)
    }
  }

}
</script>

<style lang="less">
.m-message_detail {
  .form {
  }
}
</style>
